home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / hsa_tc.arc / GR_DEMO.C next >
Text File  |  1987-09-10  |  8KB  |  305 lines

  1. /************************************************************************/
  2. /*                                                                        */
  3. /*                   G R _ D E M O . C - Demo of HSA_GRAF                    */
  4. /*                                                                        */
  5. /************************************************************************/
  6.  
  7. /************************************************************************/
  8. /*                                                                        */
  9. /*              Copyright (c) Hardwood Software Associates 1987            */
  10. /*                                                                        */
  11. /*                       Hardwood Software Associates                        */
  12. /*                              364 Benson Road                            */
  13. /*                           Northbridge, Ma 01534                        */
  14. /*                                                                        */
  15. /************************************************************************/
  16.  
  17. /************************************************************************
  18.  *            G R _ D E M O . C    E D I T    L O G
  19.  *
  20.  *    Edit    Date    Person        Modification
  21.  *    ----    ----    ------        ------------
  22.  *
  23.  ************************************************************************/
  24.  
  25. /************************************************************************
  26.  *                                                    +-------------------+
  27.  *    Author: R. Evans                                | F U N C T I O N S |
  28.  *    Date:    July, 1987                                +-------------------+
  29.  *
  30.  ************** GR_DEMO - Demo of HSA_GRAF
  31.  * SYNOPSIS:
  32.  *                gr_demo
  33.  * DESCRIPTION:
  34.  *                Demo some of the important aspects of the HSA_GRAF library.
  35.  *
  36.  ************************************************************************/
  37. #include "stdio.h"
  38. #include "hsa_gr.h"
  39. #include "ctype.h"
  40.  
  41. #define FALSE    0
  42. #define TRUE    1
  43. #define BUFFER_SIZE    16384
  44. #define XC    3000
  45. #define YC    2500
  46. #define XC1 6500
  47. #define ARCS    8
  48. #define Y_TEXT    210
  49.  
  50. int crt_type;
  51. int buffer [BUFFER_SIZE];
  52. unsigned _STACK=0x6800;
  53.  
  54. main ()
  55. {
  56. crt_type = initialize ();
  57. g_origin (1);                                    /* Origin lower left corner */
  58. do_circle ();
  59. if (crt_type != EGA)                            /* Save doesn't save full EGA */
  60.     g_save (buffer,BUFFER_SIZE);
  61. do_square ();
  62. if (crt_type != EGA)                            /* Save doesn't save full EGA */
  63.     {
  64.     g_restore (buffer,BUFFER_SIZE);
  65.     getch ();
  66.     }
  67. bye ();                                            /* All done */
  68. } /* Of gr_demo */
  69.  
  70. /************************************************************************/
  71. /*                                                                        */
  72. /*           C L E A R _ S C R E E N - Clear Screen and Draw Logo            */
  73. /*                                                                        */
  74. /************************************************************************/
  75.  
  76. void clear_screen ()
  77. {
  78. g_clr ();
  79. g_fore_color (SCR_CYAN);
  80. hsa_logo (10,4000,1300,SCR_CYAN);                /* Draw HSA Logo */
  81. g_fore_color (SCR_WHITE);
  82. } /* Of clear_screen */
  83.  
  84. /************************************************************************/
  85. /*                                                                        */
  86. /*                      D O _ S Q U A R E - Mazy Square                    */
  87. /*                                                                        */
  88. /************************************************************************/
  89. #define WIDTH    250
  90. #define SIZE    3500
  91. do_square ()
  92. {
  93. int x=2000;
  94. int y=WIDTH;
  95. register int yy;
  96. register int size=SIZE;
  97. int i;
  98.  
  99. clear_screen ();
  100. yy=5000;
  101. gs_str_h (6000,yy-=Y_TEXT,"This demo is only a");
  102. gs_str_h (6000,yy-=Y_TEXT,"very small example");
  103. gs_str_h (6000,yy-=Y_TEXT,"of what can be done");
  104. gs_str_h (6000,yy-=Y_TEXT,"using HSA_GRAF.");
  105.  
  106. gs_point (x,y);                                    /* Start it off */
  107. while (size > 4*WIDTH)
  108.     {
  109.     gs_line (-1,-1,-1,y+=size);
  110.     size -= WIDTH;
  111.     gs_line (-1,-1,x+=size,-1);
  112.     size -= WIDTH;
  113.     gs_line (-1,-1,-1,y-=size);
  114.     size -= WIDTH;
  115.     gs_line (-1,-1,x-=size,-1);
  116.     size -= WIDTH;
  117.     }
  118. size += (2*WIDTH);
  119. gs_line (-1,-1,-1,y-=WIDTH);
  120. i=2;
  121. while (size < SIZE)
  122.     {
  123.     gs_line (-1,-1,x+=size,-1);
  124.     size += (i*WIDTH);
  125.     i=1;
  126.     gs_line (-1,-1,-1,y+=size);
  127.     size += WIDTH;
  128.     gs_line (-1,-1,x-=size,-1);
  129.     size += WIDTH;
  130.     if (size > SIZE+WIDTH)
  131.         size = SIZE + WIDTH;
  132.     gs_line (-1,-1,-1,y-=size);
  133.     size += WIDTH;
  134.     }
  135. gs_line (-1,-1,x+WIDTH,-1);
  136. g_loc (&x,&y);
  137. g_fill (x-1,y+1,SCR_RED);
  138. pause ("");
  139. } /* Of do_square */
  140.  
  141. /************************************************************************/
  142. /*                                                                        */
  143. /*                   D O _ C I R C L E - Draw Some Circles                */
  144. /*                                                                        */
  145. /************************************************************************/
  146. do_circle ()
  147. {
  148. int x1;
  149. int x,y;
  150. int color = 1;
  151. int i;
  152.  
  153. clear_screen ();
  154. y=5000;
  155. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"HSA_GRAF has a single");
  156. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"simple function that");
  157. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"will draw full or");
  158. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"partial circles quickly");
  159. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"and accurately.");
  160. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"Another function will");
  161. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"fill an enclosed");
  162. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"boundary with a");
  163. gs_str_h (XC+8*(XC/10),y-=Y_TEXT,"specified color");
  164.  
  165. for (x1=XC-WIDTH;x1>2*WIDTH;x1-=WIDTH)
  166.     {
  167.     g_fore_color (SCR_WHITE);
  168.     gs_arc (x1,YC,x1,YC,XC,YC,1);
  169.     g_loc (&x,&y);
  170.     g_fore_color (color);
  171.     g_fill (x+1,y+1,color);
  172.     if (crt_type != EGA)
  173.         color = !color;
  174.     else
  175.         color++;
  176.     }
  177. gs_line (XC1-ARCS*WIDTH/2,YC,XC1+ARCS*WIDTH/2,YC);
  178. for (x1=XC1-WIDTH/2,i=0;i<ARCS;x1-=(WIDTH/2),i++)
  179.     {
  180.     g_fore_color (SCR_WHITE);
  181.     gs_arc (x1,YC,x1+2*(i+1)*(WIDTH/2),YC,XC1,YC,0);
  182.     g_loc (&x,&y);
  183.     g_fore_color (color);
  184.     g_fill (x-2,y-1,color);
  185.     if (crt_type != EGA)
  186.         color = !color;
  187.     else
  188.         color++;
  189.     }
  190. g_fore_color (SCR_WHITE);
  191. pause ("");
  192. } /* Of do_circle */
  193.  
  194. /************************************************************************/
  195. /*                                                                        */
  196. /*            I N I T I A L I Z E - Initialize for Graphics Demo            */
  197. /*                                                                        */
  198. /************************************************************************/
  199.  
  200. initialize ()
  201. {
  202. int crt_type;
  203. int x,y;
  204. int s,seg;
  205. short mode;
  206. short xdots,ydots;
  207. char buffer[80];
  208.  
  209. for (;;)
  210.     {
  211.     printf ("\n\nHSA_GRAF -  Graphics Library Demonstration\n\n");
  212.     printf ("Select graphics adapter for demonstration:\n\n");
  213.     printf ("\t1. Hercules Monochrome\n");
  214.     printf ("\t2. Color Graphics Adapter (CGA)\n");
  215.     printf ("\t3. Extended Graphics Adapter (EGA)\n");
  216.     printf ("\t4. Other brand of graphics adapter\n");
  217.     printf ("\t9. Quit\n\n");
  218.     printf ("Enter selection: ");
  219.     gets (buffer);
  220.     sscanf (buffer,"%d",&crt_type);
  221.     if (crt_type == 9)
  222.         exit (0);
  223.     if (crt_type < 1 || crt_type > 4)
  224.         continue;
  225.     switch (crt_type)
  226.         {
  227.     case 1:                                        /* Hercules Monochrome */
  228.         crt_type = MONOCHROME;
  229.         g_page (1);
  230.         break;
  231.     case 2:                                        /* Color Graphics Adapter */
  232.         crt_type = CGA;
  233.         g_cga_hr ();                            /* Initialize */
  234.         break;
  235.     case 3:                                        /* Extended Graphics Adapter */
  236.         crt_type = EGA;
  237.         g_ega_hr_co ();
  238.         break;
  239.     case 4:                                        /* Other brand */
  240.         crt_type = CGA;
  241.         printf ("Enter X,Y pixels: ");
  242.         scanf ("%d,%d",&x,&y);
  243.         printf ("Enter scans, segment: ");
  244.         scanf ("%d,%x",&s,&seg);
  245.         printf ("Enter X,Y dots per inch <640x200 = 80,37>: ");
  246.         gets (buffer);
  247.         if (strlen (buffer) > 0)
  248.             sscanf (buffer,"%d,%d",&xdots,&ydots);
  249.         else
  250.             {
  251.             xdots = 80;
  252.             ydots = 37;
  253.             }
  254.         printf ("Enter graphics mode function call <IBM = 6>: ");
  255.         gets (buffer);
  256.         if (strlen (buffer) > 0)
  257.             sscanf (buffer,"%d",&mode);
  258.         else
  259.             mode = 6;
  260.         g_other (x,y,s,seg,mode);
  261.         g_scale (x,y);
  262.         break;
  263.         }
  264.     break;
  265.     }
  266. printf ("Press any key to switch to graphics mode."); getch ();
  267. g_page(1);
  268. g_clr();
  269. disp_graph();
  270. return (crt_type);
  271.  
  272. } /* Of initialize */
  273. /************************************************************************/
  274. /*                                                                        */
  275. /*                       B Y E - All Done with GR_DEMO                    */
  276. /*                                                                        */
  277. /************************************************************************/
  278.  
  279. bye ()
  280. {
  281. disp_text(3);
  282. printf("All done\n");
  283. exit(0);
  284. } /* Of bye */
  285.  
  286. /************************************************************************/
  287. /*                                                                        */
  288. /*                    P A U S E - Wait for User Reaction                    */
  289. /*                                                                        */
  290. /************************************************************************/
  291.  
  292. pause (type)
  293. char *type;
  294. {
  295. int answer;
  296.  
  297. g_str_h (0,10,type);
  298. g_str_h (-1,-1,"Press any key to continue, \"Q\" to quit.");
  299. answer = getch ();
  300. if (toupper (answer) == 'Q')
  301.     bye ();
  302. } /* Of pause */
  303.  
  304.  
  305.